package br.com.iswe.gwt.ui.client;

import com.google.gwt.user.client.ui.TextBoxBase;

public class SameValueValidator extends BaseValidator {

	private TextBoxBase textBox1;
	private TextBoxBase textBox2;
	
	private String label2;
	
	public SameValueValidator(String nome, String label1, String label2, TextBoxBase textBox1, TextBoxBase textBox2) {
		super(nome, label1, textBox1);
		this.textBox1 = textBox1;
		this.textBox2 = textBox2;
		this.label2 = label2;
	}

	protected boolean validateImpl() {
		if( this.textBox1.getText().equals( this.textBox2.getText() ) ){
			valid(textBox1);
			valid(textBox2);
			return true;
		}
		notValid(textBox1, null);
		notValid(textBox2, commonMessages.msgValoresDiferentes(label, label2));
		return false;
	}

}
